package sg.edu.nus.iss.billing.common;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Random;
import java.util.UUID;

import sg.edu.nus.iss.billing.vo.subscription.CableTvVO;
import sg.edu.nus.iss.billing.vo.subscription.DigitalVoiceVO;
import sg.edu.nus.iss.billing.vo.subscription.MobileVoiceVO;
import sg.edu.nus.iss.billing.vo.subscription.feature.CallTransferFeatureVO;
import sg.edu.nus.iss.billing.vo.subscription.feature.DataServiceFeatureVO;
import sg.edu.nus.iss.billing.vo.subscription.feature.IDDCallFeatureVO;
import sg.edu.nus.iss.billing.vo.subscription.feature.LocalCallFeatureVO;
import sg.edu.nus.iss.billing.vo.subscription.feature.PremiumChannelFeatureVO;
import sg.edu.nus.iss.billing.vo.subscription.feature.RoamingCallFeatureVO;
import sg.edu.nus.iss.billing.vo.subscription.feature.StandardChannelFeatureVO;
import sg.edu.nus.iss.billing.vo.transaction.IddCallTransactionVO;
import sg.edu.nus.iss.billing.vo.transaction.LocalCallTransactionVO;
import sg.edu.nus.iss.billing.vo.transaction.RoamingCallTransactionVO;

public class Util {

	public static final String COMPLAINT_CLOSED = "CLOSED";
	public static final String COMPLAINT_PENDING = "PENDING";

	public static final String SUBSCRIPTION_STATUS_ACTIVE = "ACTIVE";
	public static final String SUBSCRIPTION_STATUS_INACTIVE= "INACTIVE";

	public static final String ACCOUNT_STATUS_ACTIVE = "ACTIVE";
	public static final String ACCOUNT_STATUS_INACTIVE= "INACTIVE";

	public static final String LOGIN_ROLE_UNKNOWN = "UNKNOWN_USER";
	public static final String Default_NULL = "NIL";

	public static final String SUBSCRIPTIONVO_CABLETV = "Cable TV";
	public static final String SUBSCRIPTIONVO_MOBILEVOICE = "Mobile Voice";
	public static final String SUBSCRIPTIONVO_DIGITALVOICE = "Digital Voice";

	public static final String FEATUREVO_CALLTRANSFER = "Call Transfer";
	public static final String FEATUREVO_DATASERVICE = "Data Service";
	public static final String FEATUREVO_IDDCALL = "IDD Call";
	public static final String FEATUREVO_PREMIUMCHANNEL = "Premium Channel";
	public static final String FEATUREVO_LOCALCALL = "Local Call";
	public static final String FEATUREVO_ROAMINGCALL = "Roaming Call";
	public static final String FEATUREVO_STANDARDCHANNEL = "Standard Channel";

	public static final String TRANSACTIONVO_LOCALCALL = "Local Call";
	public static final String TRANSACTIONVO_IDDCALL = "IDD Call";
	public static final String TRANSACTIONVO_ROAMINGCALL = "Roaming Call";


	private static  ArrayList<String>  ACCOUNT_STATUS = new ArrayList<String>() ;
	private static  ArrayList<String>  SUBSCRIPTION_STATUS = new ArrayList<String>() ;
	private static  ArrayList<String>  COMPLAINT_STATUS = new ArrayList<String>() ;
	private static HashMap<String, Class<?>> SUBSCRIPTIONVOMAP = new HashMap<String, Class<?>>();
	private static HashMap<String, Class<?>> FEATUREVOMAP = new HashMap<String, Class<?>>();
	private static HashMap<String, Class<?>> TRANSACTIONVOMAP = new HashMap<String, Class<?>>();


	public static void main(String[] a){
		for(int i = 0; i <10; i++){
			//System.out.println(generateRandomNumer().toUpperCase());
			System.out.println(getFormattedDate( getSystemDate()));
			System.out.println(i+" " +generateRandomPhoneNumber());
			System.out.println(i+" " +getDefaultEndDate().toString());
		}
	}

	public static  String generateRandomNumer(){
		//UUID uuid = UUID.randomUUID();
		//String myRandom = uuid.toString();
		//return myRandom.substring(10);
		String randomNumber= "";
		Random r = new Random();
		int no1 = r.nextInt(9999);
		int no2 = r.nextInt(99);
		int no3 = r.nextInt(99);
		randomNumber = String.format("%04d", no1)+"-"+String.format("%02d", no2)+"-"+String.format("%02d", no3);
		return randomNumber;
	}

	public static Date  getSystemDate()	{

		return  new java.util.Date();	 

	}

	public static String  getFormattedDate(Date date){

		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		return dateFormat.format(date);

	}

	public static String  getFormattedDate(){

		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		return dateFormat.format( new java.util.Date());

	}
	public static Date getDateFromString(String dateStr) {
		DateFormat df = new SimpleDateFormat ("dd/MM/yyyy HH:mm:ss");
		Date result = new Date();
		try {
			result = df.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return result;
	}

	public static Date getNullDate() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.YEAR, 99);
		return cal.getTime();
	}

	public static String  getFormattedDateWithoutTime(Date date){

		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		return dateFormat.format(date);

	}
	public static ArrayList<String> getListOfComplaintStatus(){
		COMPLAINT_STATUS.add(COMPLAINT_PENDING);
		COMPLAINT_STATUS.add(COMPLAINT_CLOSED);
		return COMPLAINT_STATUS;
	}

	public static ArrayList<String> getListOfAccountStatus (){
		ACCOUNT_STATUS.add(ACCOUNT_STATUS_ACTIVE);
		ACCOUNT_STATUS.add(ACCOUNT_STATUS_ACTIVE);
		return ACCOUNT_STATUS;
	}

	public static ArrayList<String> getListOfSubscriptionStatus (){
		SUBSCRIPTION_STATUS.add(SUBSCRIPTION_STATUS_ACTIVE);
		SUBSCRIPTION_STATUS.add(SUBSCRIPTION_STATUS_INACTIVE);
		return SUBSCRIPTION_STATUS;
	}

	public static HashMap<String, Class<?>> getSubscriptionVOMap() {
		// Add list of subscriptionVO classes to process.
		SUBSCRIPTIONVOMAP.put(Util.SUBSCRIPTIONVO_CABLETV, CableTvVO.class);
		SUBSCRIPTIONVOMAP.put(Util.SUBSCRIPTIONVO_DIGITALVOICE, DigitalVoiceVO.class);
		SUBSCRIPTIONVOMAP.put(Util.SUBSCRIPTIONVO_MOBILEVOICE, MobileVoiceVO.class);
		return SUBSCRIPTIONVOMAP;
	}

	public static HashMap<String, Class<?>> getFeatureVOMap() {
		// Add list of FeatureVO classes to process.
		FEATUREVOMAP.put(Util.FEATUREVO_CALLTRANSFER,  CallTransferFeatureVO.class);
		FEATUREVOMAP.put(Util.FEATUREVO_IDDCALL, IDDCallFeatureVO.class);
		FEATUREVOMAP.put(Util.FEATUREVO_DATASERVICE,  DataServiceFeatureVO.class);
		FEATUREVOMAP.put(Util.FEATUREVO_LOCALCALL,  LocalCallFeatureVO.class);
		FEATUREVOMAP.put(Util.FEATUREVO_ROAMINGCALL, RoamingCallFeatureVO.class);
		FEATUREVOMAP.put(Util.FEATUREVO_STANDARDCHANNEL,  StandardChannelFeatureVO.class);
		FEATUREVOMAP.put(Util.FEATUREVO_PREMIUMCHANNEL, PremiumChannelFeatureVO.class);
		return FEATUREVOMAP;
	} 

	public static HashMap<String, Class<?>> getTransactionVOMap() {
		// Add list of FeatureVO classes to process.
		TRANSACTIONVOMAP.put(Util.TRANSACTIONVO_LOCALCALL,  LocalCallTransactionVO.class);
		TRANSACTIONVOMAP.put(Util.TRANSACTIONVO_IDDCALL, IddCallTransactionVO.class);
		TRANSACTIONVOMAP.put(Util.TRANSACTIONVO_ROAMINGCALL,  RoamingCallTransactionVO.class);
		return TRANSACTIONVOMAP;
	} 
	public static String generateRandomPhoneNumber() {
		Random r = new Random();
		int no = r.nextInt(99999999);
		return String.format("%08d", no);
	}

	public static String generateRandomNric() {
		Random r = new Random();
		int no = r.nextInt(9999999);
		StringBuilder sb = new StringBuilder();
		sb.append("S");
		sb.append(String.format("%07d",no));
		sb.append("A");
		return sb.toString();
	}

	public static Date getDefaultEndDate() {
		Calendar calendar = Calendar.getInstance();
		calendar.set(2099, 12, 31);
		return calendar.getTime();
	}

	public static Date getRandomDateAgo(int mth) {
		Calendar calendar = Calendar.getInstance();
		Random r = new Random();
		calendar.add(Calendar.MONTH, r.nextInt(mth)*-1);
		return calendar.getTime();
	}

	public static Date getRandomDateAhead(int mth) {
		Calendar calendar = Calendar.getInstance();
		Random r = new Random();
		calendar.add(Calendar.MONTH, r.nextInt(mth));
		return calendar.getTime();
	}

	public static boolean isBetweenDate (Date minDate, Date maxDate, Date dateChecked) {
		return dateChecked.after(minDate) && dateChecked.before(maxDate); 

	}
	public static Date dateAddDays (Date date, int days) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE, days);
		return cal.getTime();

	}
	public static Date dateAddMonth (Date date, int month) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, month);
		return cal.getTime();

	}
	public static String getFileNamePattern (String accountNo, Date date) {
		DateFormat dateFormat = new SimpleDateFormat("MM_yyyy");
		return accountNo+"_"+dateFormat.format(date)+".txt";
		

	}

}
